import 'package:flutter/material.dart';
import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';
import 'package:megatron/utils/fluro.dart';

import '../const.dart';

class VideoPlay extends StatefulWidget {
  final id;
  final size;
  final length;
  final login;
  final creatorName;
  final createDate;
  final creatorDeptName;

  const VideoPlay(
      {Key key,
      this.id,
      this.size,
      this.length,
      this.login,
      this.creatorName,
      this.createDate,
      this.creatorDeptName})
      : super(key: key);

  @override
  _VideoPlayState createState() => _VideoPlayState();
}

class _VideoPlayState extends State<VideoPlay> {
  var controller = IjkMediaController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
//    DataSource source = DataSource.network('http://112.125.25.99:8000/rec/0114.flv');
//    DataSource source = DataSource.network('http://112.125.25.99:8000/rec/27574fc468ea47b5b6de7640e0ce08aa.flv');
    DataSource source =
        DataSource.network('${Const.BASEURL}/rec/${widget.id}.flv');
    controller.setDataSource(source, autoPlay: true);
  }

  @override
  void dispose() {
    controller.stop();
    controller.dispose();
  } //  // 设置播放源
//  _convertDataSource(String url) {
//    var urls = FluroConvertUtils.fluroCnParamsDecode(url).split('/');
//    String s = Uri.encodeComponent('${urls[5]}/${urls[6]}');
//    DataSource source =
//    DataSource.network('${urls[0]}//${urls[2]}/${urls[3]}/${urls[4]}/$s');
//    controller.setDataSource(source, autoPlay: true);
//  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
//        leading: IconButton(icon: Icon(Icons.arrow_back),color: Colors.white,onPressed: (){
//          controller.stop();
//          Navigator.pop(context);
//        },),
        centerTitle: true,
        title: Text(
          '记录详情',
          style: TextStyle(fontSize: 18),
        ),
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            flex: 5,
            child: IjkPlayer(
              mediaController: controller,
              controllerWidgetBuilder: (ctl) {
                return DefaultIJKControllerWidget(
                    controller: ctl,
                    doubleTapPlay: true,
                    showFullScreenButton: true,
                    hideSystemBarOnFullScreen: true);
              },
            ),
          ),
          Expanded(
            flex: 1,
            child: Container(
                color: Color(0xff333333),
                child: Padding(
                  padding: EdgeInsets.fromLTRB(15, 20, 15, 20),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text(
                            '${widget.length}  |  ${widget.size}',
                            style: TextStyle(color: Colors.white, fontSize: 16),
                          ),
                          Text(
                            '${FluroConvertUtils.fluroCnParamsDecode(widget.creatorDeptName)}  |  ${FluroConvertUtils.fluroCnParamsDecode(widget.creatorName)}',
                            style: TextStyle(color: Colors.white, fontSize: 16),
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 6,
                      ),
                      Text(
                        FluroConvertUtils.fluroCnParamsDecode(widget.createDate),
                        style: TextStyle(color: Colors.white, fontSize: 16),
                      )
                    ],
                  ),
                )),
          )
        ],
      ),
    );
  }
}
